package jcl.hash.Test测试;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;

//HashMap原码查看测试
public class Test1 {
    public static void main(String[] args) {
//        //创建两个对象
//        Test1 test1 = new Test1();
//        Test1 test2 = new Test1();
//        //调用hashCode
//        System.out.println(test1.hashCode());
//        System.out.println(test2.hashCode());
//        //一个相同引用对象
//        Test1 test3 = test1;//都指向test1对象地址
//        System.out.println(test3.hashCode());

        Student stu1 = new Student("张三", 18);
        Student stu2 = new Student("李四", 18);
        Student stu3 = new Student("张三", 18);
//        Map<Student, String> map = new HashMap<>();
        Map<Student, String> map = new HashMap<>(31);
        map.put(stu1,"111");
        map.put(stu2,"222");
        map.put(stu3,"333");
        System.out.println(map);

//        int n = 16;
//        System.out.println(17 & (n - 1));
//        System.out.println(17 % 16);
//        System.out.println(34 % 16);
//        System.out.println(34 & (n - 1));
    }
}

class Student{
    private String name;
    private int age;

//    @Override
//    public int hashCode() {
//        return Objects.hash(name, age);
//    }


        @Override
    public int hashCode() {
        return 0;
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
       if(this == o){
           //说明此事地址相同，是同一个对象
           return true;
       }
       //如果此时的 o 是个学生类披着Object的外衣
       if(o instanceof Student){
           //需要强制类型转换
           Student stu = (Student) o;
           return this.age == stu.age && this.name.equals(stu.name);
       }
       return false;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}